from enthought.traits.api import HasTraits, Instance
from enthought.traits.ui.api import View, Item
from enthought.chaco.api import Plot, ArrayPlotData
from enthought.enable.component_editor import ComponentEditor
from enthought.traits.api import HasTraits,Int,Float,Str,Property,Range,Array
from enthought.traits.ui.api import View,Item,Label
from enthought.chaco.chaco_plot_editor import ChacoPlotItem
from numpy import cos, linspace, sin, tan

class OverlappingPlot(HasTraits):
    plot = Instance(Plot)
    
    slider = Range(0.0, 10.0)
    x = Float
    offset = Property(Float,depends_on=["slider"])
    
    def _slider_default(self): return 0
    
    def _get_offset(self):return self.slider
    
        
    traits_view = View(
        Item('plot',editor=ComponentEditor(), show_label=False),
        Item('slider'),
        width=1000, height=500, resizable=True, title="Chaco Plot")
    def __init__(self):
        super(OverlappingPlot, self).__init__()
        
    
        
        #creates a list to store the x and y values
        x = list()
        y = list()
        
        #these are the individual datasets for each line
        xx = linspace(-14, 14, 100)
        yy = sin(xx)
        
        #creates the ArrayPlotdata object
        plotdata = ArrayPlotData()
        
        #this loads the different lines into the ArrayPlotData object
        i = 0
        while i < 50:
            x.append(xx + self.offset)
            y.append(yy*(1+i) + self.offset)       
            plotdata.set_data("x"+str(i+1), x[i])
            plotdata.set_data("y"+str(i+1), y[i])
            i = i + 1
         
        #Gives plot data the information it needs 
        plot = Plot(plotdata)  
        
        #This plots each line
        i = 0
        while i < 50:      
            plot.plot(("x"+str(i+1), "y"+str(i+1)), type="line", color="black")
            i = i + 1
            self.plot = plot
        
        
if __name__ == "__main__":
    OverlappingPlot().configure_traits()